using Engine;
using Game;
using GameEntitySystem;

namespace SCIENEW {
    /// <summary>
    /// 机器特殊值三位，前两位是机器朝向，后一位是机器是否为亮着的
    /// </summary>
    public class IronFurnaceDevice : FourDirectionModelDevice, ICrafterDevice<ComponentIronFurnace>, IElectricElementDevice {
        public IronFurnaceDevice() : base("IronFurnaceDevice", "Models/IronFurnace", "Furnace") { }

        public override int GetEmittedLightAmount(int value) => IsLight(value) ? 13 : 0;

        public override float GetHeat(int value) => IsLight(value) ? 0.66f : 0;

        public override bool IsFaceTransparent(SubsystemTerrain subsystemTerrain, int face, int value) => IsLight(value);

        public override bool IsTransparent_(int value) => IsLight(value);

        public override int GetShadowStrength(int value) => IsLight(value) ? -99 : base.GetShadowStrength(value);

        protected static bool IsLight(int value) => DevicesUtils.GetInnerData(value) >> 2 == 1;

        public string GetEntityName(int value) => "IronFurnace";

        public Widget GetWidget(IInventory inventory, ComponentIronFurnace component) => new IronFurnaceWidget(inventory, component);

        public override DeviceBehavior[] GetBehaviors(Project project) => [new IronFurnaceDeviceBehavior(project)];

        public ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z) => new CrafterPopResultsElectricElement(subsystemElectricity, new Point3(x, y, z), GetDirection(value));

        public ElectricConnectorType? GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z) => ElectricConnectorType.Input;

        public int GetConnectionMask(int value) => int.MaxValue;
    }
}